﻿/*
 * Created by SharpDevelop.
 * User: IEscarro
 * Date: 8/25/2009
 * Time: 9:26 AM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
using Miming.Model;

namespace Miming.Gui
{
	/// <summary>
	/// Description of VendorListForm.
	/// </summary>
	public partial class VendorListForm : BaseForm
	{
		public VendorListForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			listView1.Resize += delegate { columnHeader1.Width = listView1.Width - 22 - (columnHeader2.Width); };
			newToolStripMenuItem.Click += delegate { MainForm.Instance.AddChild(new VendorForm()); };
		}
		
		[System.ComponentModel.EditorBrowsableAttribute()]
		protected override void OnActivated(EventArgs e)
		{
			base.OnActivated(e);
			Model = SessionFacade.FindAllVendors();
		}
		
		protected override void OnModelChanged(EventArgs e)
		{
			base.OnModelChanged(e);
			listView1.Items.Clear();
			foreach (Vendor v in Model as IList<Vendor>) {
				ListViewItem li = listView1.Items.Add(v.Name);
			}
		}
		
		void ListView1DoubleClick(object sender, EventArgs e)
		{
			if (listView1.SelectedItems.Count > 0) {
				Vendor v = (Model as IList<Vendor>)[listView1.SelectedItems[0].Index];
				MainForm.Instance.AddChild(new VendorForm(v), "Edit Vendor");
			}
		}
	}
}
